<html>
<head>
<title>EditListActivity.java</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<style type="text/css">
.ln { color: rgb(0,0,0); font-weight: normal; font-style: normal; }
.s0 { color: rgb(0,0,128); font-weight: bold; }
.s1 { }
.s2 { color: rgb(0,0,255); }
.s3 { color: rgb(0,128,0); font-weight: bold; }
.s4 { color: rgb(128,128,128); font-style: italic; }
.s5 { color: rgb(128,128,128); font-weight: bold; font-style: italic; }
</style>
</head>
<BODY BGCOLOR="#ffffff">
<TABLE CELLSPACING=0 CELLPADDING=5 COLS=1 WIDTH="100%" BGCOLOR="#C0C0C0" >
<TR><TD><CENTER>
<FONT FACE="Arial, Helvetica" COLOR="#000000">
EditListActivity.java</FONT>
</center></TD></TR></TABLE>
<pre>

<span class="s0">package </span><span class="s1">com.example.lista_zakupow.activities.shop_list; 
 
</span><span class="s0">import </span><span class="s1">android.app.Activity; 
</span><span class="s0">import </span><span class="s1">android.app.AlertDialog; 
</span><span class="s0">import </span><span class="s1">android.app.Dialog; 
</span><span class="s0">import </span><span class="s1">android.content.DialogInterface; 
</span><span class="s0">import </span><span class="s1">android.content.Intent; 
</span><span class="s0">import </span><span class="s1">android.os.Bundle; 
</span><span class="s0">import </span><span class="s1">android.view.View; 
</span><span class="s0">import </span><span class="s1">android.widget.Button; 
</span><span class="s0">import </span><span class="s1">android.widget.EditText; 
</span><span class="s0">import </span><span class="s1">com.example.lista_zakupow.R; 
</span><span class="s0">import </span><span class="s1">com.example.lista_zakupow.activities.MainActivity; 
</span><span class="s0">import </span><span class="s1">com.example.lista_zakupow.database.dao.ListaZakupowDao; 
</span><span class="s0">import </span><span class="s1">com.example.lista_zakupow.zakupy.ListaZakupow; 
 
</span><span class="s0">public class </span><span class="s1">EditListActivity </span><span class="s0">extends </span><span class="s1">Activity { 
    </span><span class="s0">public static final int </span><span class="s1">NO_TASK_TAME_DIALOG = </span><span class="s2">1</span><span class="s1">; 
 
    </span><span class="s0">private </span><span class="s1">EditText editTextTaskName; 
 
    </span><span class="s0">private </span><span class="s1">ListaZakupowDao listaZakupowDao; 
    ListaZakupow listaZakupow; 
 
    @Override 
    </span><span class="s0">protected void </span><span class="s1">onCreate(Bundle savedInstanceState) { 
        </span><span class="s0">super</span><span class="s1">.onCreate(savedInstanceState); 
        setContentView(R.layout.add_and_edit_list); 
 
        listaZakupow = (ListaZakupow)getIntent().getExtras().get(</span><span class="s3">&quot;lista&quot;</span><span class="s1">); 
 
        listaZakupowDao = </span><span class="s0">new </span><span class="s1">ListaZakupowDao(</span><span class="s0">this</span><span class="s1">); 
        editTextTaskName = (EditText) findViewById(R.id.listNameEditText); 
        editTextTaskName.setText(listaZakupow.getNameToView()); 
 
        Button saveBtn = (Button) findViewById(R.id.buttonSave); 
 
        saveBtn.setOnClickListener(</span><span class="s0">new </span><span class="s1">OnSaveClickListener()); 
    } 
 
    </span><span class="s4">/** 
     * Okno dialogowe 
     * </span><span class="s5">@param </span><span class="s4">id nr okna dialogowego 
     * </span><span class="s5">@return </span><span class="s4">okno dialogowe 
     */</span><span class="s1"> 
    @Override 
    </span><span class="s0">protected </span><span class="s1">Dialog onCreateDialog(</span><span class="s0">int </span><span class="s1">id) { 
        </span><span class="s0">switch </span><span class="s1">(id) { 
            </span><span class="s0">case </span><span class="s1">NO_TASK_TAME_DIALOG: { 
                </span><span class="s0">return new </span><span class="s1">AlertDialog.Builder(</span><span class="s0">this</span><span class="s1">) 
                        .setMessage(</span><span class="s3">&quot;Nie wpisałeś nazwy&quot;</span><span class="s1">) 
                        .setPositiveButton(</span><span class="s3">&quot;OK&quot;</span><span class="s1">, </span><span class="s0">new </span><span class="s1">DialogInterface.OnClickListener() { 
                            @Override 
                            </span><span class="s0">public void </span><span class="s1">onClick(DialogInterface arg0, </span><span class="s0">int </span><span class="s1">arg1) { 
                            } 
                        }).create(); 
            } 
        } 
        </span><span class="s0">return null</span><span class="s1">; 
    } 
 
    </span><span class="s4">/** 
     * Sluchacz  przycisku zapisz 
     */</span><span class="s1"> 
    </span><span class="s0">private class </span><span class="s1">OnSaveClickListener </span><span class="s0">implements </span><span class="s1">View.OnClickListener { 
        @Override 
        </span><span class="s0">public void </span><span class="s1">onClick(View view) { 
            </span><span class="s0">if </span><span class="s1">(editTextTaskName.getText().toString().equals(</span><span class="s3">&quot;&quot;</span><span class="s1">)) 
                showDialog(NO_TASK_TAME_DIALOG); 
            </span><span class="s0">else </span><span class="s1">{ 
                listaZakupow.setName(editTextTaskName.getText().toString()); 
                listaZakupowDao.update(listaZakupow); 
                wrocDoGlownejAkt(); 
            } 
        } 
    } 
 
    </span><span class="s0">private void </span><span class="s1">wrocDoGlownejAkt() { 
        Intent intent = </span><span class="s0">new </span><span class="s1">Intent(getApplicationContext(), MainActivity.</span><span class="s0">class</span><span class="s1">); 
        startActivity(intent); 
    } 
} 
</span></pre>
</body>
</html>